package com.xyz.messagehelper.broad_cast_reciver

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.app.Activity
import android.telephony.SmsManager;
import android.util.Log
import com.xyz.messagehelper.bean.ConstantValue
import com.xyz.messagehelper.bean.ConstantValue.SEND_MESSAGE_SUCCESS
import com.xyz.messagehelper.bean.ConstantValue.SENT_MESSAGE_FAIL
import com.xyz.messagehelper.bean.ConstantValue.SENT_MESSAGE_SUCCESS
import com.xyz.messagehelper.bean.ConstantValue.SMS_DELIVERED_ACTION
import com.xyz.messagehelper.bean.ConstantValue.SMS_SEND_ACTIOIN
import com.xyz.messagehelper.bean.MessageEvent
import org.greenrobot.eventbus.EventBus

class SMSReceiver : BroadcastReceiver() {

    override fun onReceive(context: Context?, intent: Intent?) {
        if (intent?.action.equals(SMS_DELIVERED_ACTION)) {
            when (resultCode) {
                Activity.RESULT_OK -> {
                    EventBus.getDefault().post(MessageEvent(ConstantValue.SENT_MESSAGE_SUCCESS))
                }
                SmsManager.RESULT_ERROR_GENERIC_FAILURE -> {
                    EventBus.getDefault().post(MessageEvent(SENT_MESSAGE_FAIL))
                }
            }
        }
    }

}